
package com.jf.cloud.supplier.controller.supplier;

import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.common.security.AuthUserContext;
import com.jf.cloud.supplier.dto.SupplierBankCardDTO;
import com.jf.cloud.supplier.service.SupplierBankCardService;
import com.jf.cloud.supplier.vo.SupplierBankCardVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author zz
 * @Date 2021/4/29 10:11
 */
@RestController("supplierSupplierBankCardController")
@RequestMapping("/s/apply_supplier/supplier_bank_card")
@Tag(name = "supplier-店铺银行卡信息")
public class SupplierBankCardController {

    @Autowired
    private SupplierBankCardService supplierBankCardService;

    @PostMapping("/save_and_apply_supplier")
    @Operation(summary = "批量保存店铺银行卡信息并提交店铺审核信息" , description = "批量保存店铺银行卡信息并提交店铺审核信息")
    public ServerResponseEntity<Void> saveAndApplySupplier(@Valid @RequestBody List<SupplierBankCardDTO> supplierBankCardDTOList) {
        Long supplierId = AuthUserContext.get().getTenantId();
        supplierBankCardService.insertBatchAndSubmitApply(supplierBankCardDTOList, supplierId);
        return ServerResponseEntity.success();
    }

    @GetMapping
    @Operation(summary = "根据银行卡id获取银行卡信息" , description = "根据银行卡id获取银行卡信息")
    public ServerResponseEntity<SupplierBankCardVO> getById(@RequestParam("supplierBankCardId") Long supplierBankCardId) {
        Long supplierId = AuthUserContext.get().getTenantId();
        SupplierBankCardVO supplierBankCardVO = supplierBankCardService.getBySupplierBankCardIdAndSupplierId(supplierBankCardId, supplierId);
        return ServerResponseEntity.success(supplierBankCardVO);
    }

    @GetMapping("/list_by_supplierId")
    @Operation(summary = "获取店铺下的银行卡列表" , description = "获取店铺下的银行卡列表")
    public ServerResponseEntity<List<SupplierBankCardVO>> listBySupplierId() {
        Long supplierId = AuthUserContext.get().getTenantId();
        List<SupplierBankCardVO> supplierBankCardVOList = supplierBankCardService.listBySupplierId(supplierId);
        return ServerResponseEntity.success(supplierBankCardVOList);
    }

    @PostMapping
    @Operation(summary = "添加单个银行卡信息" , description = "添加单个银行卡信息")
    public ServerResponseEntity<Void> insert(@RequestBody @Valid SupplierBankCardDTO supplierBankCardDTO) {
        Long supplierId = AuthUserContext.get().getTenantId();
        supplierBankCardService.insertBySupplierId(supplierBankCardDTO, supplierId);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "根据银行卡id删除银行卡信息" , description = "根据银行卡id删除银行卡信息")
    public ServerResponseEntity<Void> deleteById(@RequestParam(value = "supplierBankCardId") Long supplierBankCardId) {
        supplierBankCardService.deleteBySupplierBankCardId(supplierBankCardId, AuthUserContext.get().getTenantId());
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新银行卡信息" , description = "更新银行卡信息")
    public ServerResponseEntity<Void> update(@RequestBody @Valid SupplierBankCardDTO supplierBankCardDTO) {
        supplierBankCardService.updateBySupplierId(supplierBankCardDTO, AuthUserContext.get().getTenantId());
        return ServerResponseEntity.success();
    }

    @PutMapping("/set_primary")
    @Operation(summary = "设置为主账号" , description = "设置为主账号")
    public ServerResponseEntity<Void> setPrimary(@RequestParam(value = "supplierBankCardId") Long supplierBankCardId) {
        supplierBankCardService.setPrimaryBySupplierId(supplierBankCardId, AuthUserContext.get().getTenantId());
        return ServerResponseEntity.success();
    }

    @PutMapping("/set_not_primary")
    @Operation(summary = "取消主账号" , description = "取消主账号")
    public ServerResponseEntity<Void> setNotPrimary(@RequestParam(value = "supplierBankCardId") Long supplierBankCardId) {
        supplierBankCardService.setNotPrimaryBySupplierId(supplierBankCardId, AuthUserContext.get().getTenantId());
        return ServerResponseEntity.success();
    }
}
